<?php

class Sgit_Util_getFiles
{

    static public function run($tabla, $key, $id,$addpath=false)
    {
        $dirname = PUBLIC_DOCUMENT . "/$tabla/$key/$id";
        $dirpublic = WEB_DOCUMENT_PATH. "/$tabla/$key/$id/";


        if(file_exists($dirname)){
            $dir = new DirectoryIterator($dirname);
            foreach ($dir as $fileinfo)
            {
                if ($fileinfo->isFile())
                {
                    if($addpath){
                        $a=pathinfo($fileinfo->getPathname());
                        $a['basename']=utf8_encode($a['basename']);
                        $a['public_path']=$dirpublic.$a['basename'];
                        $a['pathname']=$fileinfo->getPathname();
                        $a['size']=$fileinfo->getSize();
                        $a['time']=new Zend_Date($fileinfo->getCTime());
                        $a['extension']=$a['extension'];
                        
                        $files[] =$a;
                    }else{
                        $files[] = utf8_encode($fileinfo->getBasename());
                    }
                }
            }
            


            return $files;
        }
    }

}
